import request from '@/config/axios'

export interface WarehouseVO {
  id: number
  name: string
  code: string
  type: number
  openPosition: number
  openNegative: number
  openSalf: number
  openReorder: number
  address: string
  plantId: number
  status: number
  sort: number
  remark: string
}

// 查询仓库分页
export const getWarehousePage = async (params) => {
  return await request.get({ url: `/wms/warehouse/page`, params })
}

// 查询仓库详情
export const getWarehouse = async (id: number) => {
  return await request.get({ url: `/wms/warehouse/get?id=` + id })
}

// 新增仓库
export const createWarehouse = async (data: WarehouseVO) => {
  return await request.post({ url: `/wms/warehouse/create`, data })
}

// 修改仓库
export const updateWarehouse = async (data: WarehouseVO) => {
  return await request.put({ url: `/wms/warehouse/update`, data })
}

// 删除仓库
export const deleteWarehouse = async (id: number) => {
  return await request.delete({ url: `/wms/warehouse/delete?id=` + id })
}

// 导出仓库 Excel
export const exportWarehouse = async (params) => {
  return await request.download({ url: `/wms/warehouse/export-excel`, params })
}

// 查询仓库树形结构
export const getWarehouseTree = async () => {
  return await request.get({ url: `/wms/warehouse/tree`})
}

// ==================== 子表（库位） ====================

// 获得库位分页
export const getPositionPage = async (params) => {
  return await request.get({ url: `/wms/warehouse/position/page`, params })
}
// 新增库位
export const createPosition = async (data) => {
  return await request.post({ url: `/wms/warehouse/position/create`, data })
}

// 修改库位
export const updatePosition = async (data) => {
  return await request.put({ url: `/wms/warehouse/position/update`, data })
}

// 删除库位
export const deletePosition = async (id: number) => {
  return await request.delete({ url: `/wms/warehouse/position/delete?id=` + id })
}

// 获得库位
export const getPosition = async (id: number) => {
  return await request.get({ url: `/wms/warehouse/position/get?id=` + id })
}
